#9—1
class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
    def describe_restaurant(self):
        print('The restaurant’s name is' + self.restaurant_name)
        print('The restaurant’s cuisine is' + self.cuisine_type)
    def open_restaurant(self):
        print(self.restaurant_name + 'is open')
restaurant = Restaurant(' A',' B')
print(restaurant.restaurant_name,'',restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant

#9—2
class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
    def describe_restaurant(self):
        print('The restaurant’s name is ' + self.restaurant_name)
        print('The restaurant’s cuisine is ' + self.cuisine_type)
    def open_restaurant(self):
        print(self.restaurant_name + 'is open')
restaurant1 = Restaurant('C','D')
restaurant2 = Restaurant('E','F')
restaurant3 = Restaurant('X','Y')


restaurant1.describe_restaurant()
restaurant2.describe_restaurant()
restaurant3.describe_restaurant()

#9—3
class User():
    def __init__(self,first_name,last_name,country):
        self.first_name = first_name
        self.last_name = last_name
        self.country = country

    def describe_user(self):
        print('The user‘name is  ' + self.first_name + self.last_name)
        print('It’s from ' + self.country)

    def geeet_user(self):
        print('你好' + self.first_name + self.last_name)
user1 = User('A','B','C')
user2 = User('1','2','3')

user1.describe_user()
user1.geeet_user()

user2.describe_user()
user2.geeet_user()

#9—4
class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
        self.number_served = 0

    def describe_restaurant(self):
        print("The restaurant's name is " + self.restaurant_name)
        print("The restaurant's cuisine type is " + self.cuisine_type)

    def open_restaurant(self):
        print(self.restaurant_name + " 正在营业")

    def set_number_served(self,number_served):
        self.number_served = number_served

    def increment_number_served(self,additional_served):
        self.number_served += additional_served

restaurant = Restaurant('A', 'B')
restaurant.describe_restaurant()

print("\nNumber served: " + str(restaurant.number_served))
restaurant.number_served = 20
print("Number served: " + str(restaurant.number_served))

restaurant.set_number_served(100)
print("Number served: " + str(restaurant.number_served))

restaurant.increment_number_served(50)
print("Number served: " + str(restaurant.number_served))
#9-5 尝试登录次数 尝 ：在为完成练习9-3而编写的User 类中，添加一个名为login_attempts 的属性。
# 编写一个名为increment_login_attempts() 的方法， 它将属性login_attempts 的值加1。
# 再编写一个名为reset_login_attempts() 的方法，它将属性login_attempts 的值重置为0。
# 根据User 类创建一个实例，再调用方法increment_login_attempts() 多次。打印属性login_attempts 的值，确认它被正确地递增；
# 然后，调用方 法reset_login_attempts() ，并再次打印属性login_attempts 的值，确认它被重置为0。
class User():
    def __init__(self,first_name,last_name):
        self.first_name=first_name
        self.last_name=last_name
        self.login_attempts=0

    def describe_user(self):
        print('用户的性为'+self.first_name)
        print('用户的名为'+self.last_name)
    def greet_user(self):
        print('Hello'+self.first_name+self.last_name)
    def increment_login_attempts(self):
        print(str(self.login_attempts))
    def reset_login_attempts(self,number):
        self.login_attempts+=number


print('\n')
userA=User('mao','zihao')
userB=User('zhu','yifan')
userA.describe_user()
userB.describe_user()
userA.greet_user()
userB.greet_user()
userA.reset_login_attempts(0)
userA.increment_login_attempts()

#9-6 冰淇淋小店 冰 ：冰淇淋小店是一种特殊的餐馆。
# 编写一个名为IceCreamStand 的类，让它继承你为完成练习9-1或练习9-4而编写的Restaurant 类
# 。这两个版 本的Restaurant 类都可以，挑选你更喜欢的那个即可。添加一个名为flavors 的属性，用于存储一个由各种口味的冰淇淋组成的列表
# 。编写一个显示这些冰淇淋 的方法。创建一个IceCreamStand 实例，并调用这个方法。
class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
    def describe_restaurant(self):
        print(self.restaurant_name)
        print(self.cuisine_type)
    def open_restaurant(self):
        print("正在营业")

class IceCreamStand(Restaurant):
    def __init__(self,restaurant_name,cuisine_type):
        super().__init__(restaurant_name,cuisine_type)
        self.flavors = []

    def show_flavors(self):
        for flavor in self.flavors:
            print("This is a " + flavor + " flavored ice cream.")


iceCreamStand = IceCreamStand('A','ice cream')
iceCreamStand.flavors = ['B','C']
iceCreamStand.describe_restaurant()
iceCreamStand.show_flavors()

#9-7 管理员 管 ：管理员是一种特殊的用户。编写一个名为Admin 的类，让它继承你为完成练习9-3或练习9-5而编写的User 类。
# 添加一个名为privileges 的属性，用 于存储一个由字符串（如"can add post" 、"can delete post" 、"can ban user" 等）组成的列表。
# 编写一个名为show_privileges() 的方法，它 显示管理员的权限。创建一个Admin 实例，并调用这个方法。
class User():
    def __init__(self,first_name,last_name):
        self.first_name = first_name
        self.last_name = last_name

    def describe_user(self):
        print("The user's name is " + self.first_name + self.last_name)

    def greet_user(self):
        print("Hello," + self.first_name + self.last_name)

class Admin(User):
    def __init__(self,first_name,last_name):
        super().__init__(first_name,last_name)
        self.privileges = Privileges()

class Privileges():
    def __init__(self,privileges=[]):
        self.privileges = privileges

    def show_privileges(self):
        for privilege in self.privileges:
            print("Admin" + privilege)

admin = Admin('Michael','Jordan')
admin.privileges.privileges = [' can add post',' can delete post',' can ban user']
admin.privileges.show_privileges()

#9-8 权限权 ：编写一个名为Privileges 的类，它只有一个属性——privileges ，其中存储了练习9-7 所说的字符串列表。
# 将方法show_privileges() 移到这 个类中。在Admin 类中，将一个Privileges 实例用作其属性。
# 创建一个Admin 实例，并使用方法show_privileges() 来显示其权限。
class User():
    def __init__(self,first_name,last_name):
        self.first_name = first_name
        self.last_name = last_name

    def describe_user(self):
        print(self.first_name + self.last_name)

    def greet_user(self):
        print(self.first_name + self.last_name)

class Admin(User):
    def __init__(self,first_name,last_name):
        super().__init__(first_name,last_name)
        self.privileges = Privileges()

class Privileges():
    def __init__(self,privileges=[]):
        self.privileges = privileges

    def show_privileges(self):
        for privilege in self.privileges:
            print("Admin" + privilege)

admin = Admin('Michael','Jordan')
admin.privileges.privileges = [' can add post',' can delete post',' can ban user']
admin.privileges.show_privileges()
#9-9 电瓶升级 电 ：在本节最后一个electric_car.py版本中，给Battery 类添加一个名为upgrade_battery() 的方法。
# 这个方法检查电瓶容量，如果它不是85，就将它 设置为85。
# 创建一辆电瓶容量为默认值的电动汽车，调用方法get_range() ，然后对电瓶进行升级，并再次调用get_range() 。
# 你会看到这辆汽车的续航里程增加了。
class Car():
    def __init__(self,make,model,year):
        self.make = make
        self.model = model
        self.year = year

    def get_descriptive_name(self):
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model
        return long_name.title()

class Battery():
    def __init__(self,battery_size=70):
        self.battery_size = battery_size

    def descriptive_battery(self):
        print(str(self.battery_size))

    def get_range(self):
        if self.battery_size == 70:
            range = 240
        elif self.battery_size == 85:
            range = 270

        message =  str(range)
        print(message)

    def upgrade_battery(self):
        if self.battery_size != 85:
            self.battery_size = 85

class ElectricCar(Car):
    def __init__(self,make,model,year):
        super().__init__(make,model,year)
        self.battery = Battery()

my_tesla = ElectricCar('tesla','model s',2020)

my_tesla.battery.get_range()
my_tesla.battery.upgrade_battery()
my_tesla.battery.get_range()

#9-10 导入导 Restaurant 类 ：将最新的Restaurant 类存储在一个模块中。在另一个文件中，导入Restaurant 类，
# 创建一个Restaurant 实例，并调 用Restaurant 的一个方法，以确认import 语句正确无误。
class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        self.name = restaurant_name
        self.type = cuisine_type
        self.number_served = 0
    def describe_restaurant(self):
        print("My "+self.name+" is the first home.")
        print("This is my favorite "+self.name)
    def open_restaurant(self):
        print("There are the "+ self.type.title())
        print("There are "+str(self.number_served)+" have a dinner .")
my_restaurant=Restaurant('quanjude','chinese food')
my_restaurant.number_served = 36
print(my_restaurant.name)
print(my_restaurant.type)
my_restaurant.describe_restaurant()
my_restaurant.open_restaurant()


#9-11 导入导 Admin 类 ：以为完成练习9-8而做的工作为基础，将User 、Privileges 和Admin 类存储在一个模块中，再创建一个文件，
# 在其中创建一个Admin 实例 并对其调用方法show_privileges() ，以确认一切都能正确地运行。
class User():
    def __init__(self,first_name,last_name):
        self.first = first_name
        self.last = last_name
    def describe_user(self):
        print("I want to add  "+self.first+" in my car.")
        print("I want to add " + self.last + " in my car too.")
    def greet_user(self):
        print("OK sir,we will do well it,It's a pleasure to serve you.")

class Privileges():
    def __init__(self,privileges= ['can add post','can delete post','can ban user']):
        self.privileges = privileges
    def show_privileges(self):
        while self.privileges:
            message = self.privileges.pop()
            print(message)


class Admin(User):
    def __init__(self,first_name,last_name):
        super().__init__(first_name,last_name)
        self.privileges = Privileges()
    def show_privileges(self):
        print(self.privileges)



my_admin = Admin('dageng','caisedeng')
print(my_admin.describe_user())
my_admin.privileges.show_privileges()


#9-12 多个模块 多 ：将User 类存储在一个模块中，并将Privileges 和Admin 类存储在另一个模块中。
# 再创建一个文件，在其中创建一个Admin 实例，并对其调用方 法show_privileges() ，以确认一切都依然能够正确地运行。
class Privileges():
    def __init__(self,privileges= ['can add post','can delete post','can ban user']):
        self.privileges = privileges
    def show_privileges(self):
        while self.privileges:
            message = self.privileges.pop()
            print(message)

from  use  import User
class Admin(User):
    def __init__(self,first_name,last_name):
        super().__init__(first_name,last_name)
        self.privileges = Privileges()
    def show_privileges(self):
        print(self.privileges)







